package com.mz.mattress.client.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mz.mattress.api.entity.MemberMer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MemberMerMapper extends BaseMapper<MemberMer> {

    @Select("select balance from mz_member_mer where id=#{memberId} for update")
    Integer lockMember(@Param("memberId") Long memberId);

//    @Update("update mz_member_mer set balance=balance+#{change} where id=#{memberId}")
//    void updateBalance(@Param("memberId") Long memberId, @Param("change") Integer change);

    //更新收益
    @Update("update mz_member_mer set balance=balance+#{change},sum_income=sum_income+#{change} where id=#{memberId}")
    void addBalance(@Param("memberId") Long memberId, @Param("change") Integer change);

//    @Update("update biz_member set balance=balance+#{change},version=version+1 where id=#{memberId} and version=#{version}")
//    Integer updateBalance(@Param("memberId") Long memberId, @Param("change") Integer change);

    //提现使用
    @Update("update mz_member_mer set balance=balance+#{change},sum_cash_out=sum_cash_out+#{change} where id=#{memberId}")
    void subtractBalance(@Param("memberId") Long memberId, @Param("change") Integer change);

}
